package com.aaa.service.impl;


import com.aaa.common.domain.ContractInfo;
import com.aaa.common.domain.RenterInfo;
import com.aaa.common.query.ConditionalQuery;
import com.aaa.common.query.PageQuery;
import com.aaa.common.result.Result;
import com.aaa.mapper.OwnAssetsContractInfoMapper;
import com.aaa.service.OwnAssetsContractInfoService;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;




/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 宋文森
 * @Date: 2021/01/26/14:01
 * @Description:
 */
@Service
public class OwnAssetsContractServiceImpl implements OwnAssetsContractInfoService {

  @Autowired
  OwnAssetsContractInfoMapper mapper;


    /**
     * 查询所有的合同信息（分页）
     * PageHelper 分页插件
     * @param pageQuery
     * @return Result
     */
    public Result listAll(PageQuery pageQuery) {
        Page<ContractInfo> objects = new Page<>(pageQuery.getCurrentPage(),pageQuery.getPageCount());
        Page<ContractInfo> contractInfos = mapper.listContract(objects);
        if (contractInfos!=null){
            return  Result.success(contractInfos);
        }
        return  Result.error("查询失败!");
    }


    /**
     * 条件查询
     * @param conditionalQuery
     * @return
     */
    public Result conditionalQuery(ConditionalQuery conditionalQuery) {
        Page<ContractInfo> page = new Page<>(conditionalQuery.getCurrentPage(),conditionalQuery.getPageCount());
        Page<ContractInfo> contractInfos = mapper.conditionalQuery(page,conditionalQuery.getContractId(),conditionalQuery.getAssetId(),conditionalQuery.getLessee(),conditionalQuery.getCompanyName(),conditionalQuery.getContractStatusId());
        if (contractInfos!=null){
            return Result.success(contractInfos);
        }
        return Result.error("自有资产出租合同信息条件查询失败");
    }

    /**
     * 自有资产租出合同修改操作
     * @param contractInfo
     * @return
     */

    public boolean updateById(ContractInfo contractInfo) {
        int i = mapper.updateById(contractInfo);
        if (i>0){
            return true;
        }
        return false;
    }

    /**
     * 自有资产租出合同添加时的租户信息添加并返回自增列id
     * @param renterInfo
     * @return
     */
    @Override
    public Integer insertRenter(RenterInfo renterInfo) {
        return mapper.insertRenter(renterInfo);
    }
}
